// 标签设置
import React, { useState } from 'react';
import { Switch, Select, InputNumber } from 'antd';
import Editor from 'src/pages/AnalyseManage/EditReport/components/EditorStyleType/Editor';
import FormItem from 'antd/lib/form/FormItem';
import InputColorPicker from 'src/pages/AnalyseManage/EditReport/components/EditorStyleType/InputColorPicker';
const { Option } = Select;

interface IProps {
	config: any;
	onValuesChange: ( chartType: string, key: string, values: Object, configType: string ) => void;
	form: any;
}

const LineLabelSetting = ( props: IProps ) => {
	const { config, onValuesChange, form } = props;

	const fontConfig = [ 'fontFamily', 'fontSize', 'fontColor', 'fontBold', 'fontItalic' ];
	const [ isShowLabelData, setIsShowLabelData ] = useState(
		config.style && config.style.hasOwnProperty( 'isShowLabelData' ) ? config.style.isShowLabelData : false
	);
	const [ onlyShowLabelMax, setOnlyShowLabelMax ] = useState(
		config.style && config.style.hasOwnProperty( 'onlyShowLabelMax' ) ? config.style.onlyShowLabelMax : false
	);
	const [ onlyShowLabelMin, setOnlyShowLabelMin ] = useState(
		config.style && config.style.hasOwnProperty( 'onlyShowLabelMin' ) ? config.style.onlyShowLabelMin : false
	);

	const [ chartLabelMarkColor, setChartLabelMarkColor ] = useState( config.style.chartLabelMarkColor || '' );


	// const [ chartLabelMarkType, setChartLabelMarkType ] = useState(
	// 	config.style && config.style.hasOwnProperty( 'chartLabelMarkType' ) ? config.style.chartLabelMarkType : 'diamond'
	// );

	const onChange = ( checked: boolean, name: string, cb: any ) => {
		cb && cb();
		form.setFieldsValue( { [name]: checked } );
		onValuesChange( config.type, config.key, { [name]: checked }, 'style' );
	};

	const onColorChange = ( color ) => {
		setChartLabelMarkColor( color );
		form.setFieldsValue( { chartLabelMarkColor: color } );
		onValuesChange( config.type, config.key, { chartLabelMarkColor: color }, 'style' );
	};

	// 是否显示数据，仅显示最大数据，仅显示最小数据，标签字体（字体、大小、颜色、粗细、斜体），
	// 标记样式（实心圆、空心圆、菱形、三角形、正方形），标记大小
	return (
		<div>
			<FormItem label="是否显示数据" name="isShowLabelData" labelAlign="left" labelCol={{ span: 8 }} wrapperCol={{ span: 16 }}>
				<Switch
					checked={isShowLabelData}
					onChange={( checked ) => onChange( checked, 'isShowLabelData', setIsShowLabelData( checked ) )}
				></Switch>
			</FormItem>
			{isShowLabelData && (
				<>
					<FormItem label="显示最大值" name="onlyShowLabelMax" labelAlign="left" labelCol={{ span: 8 }} wrapperCol={{ span: 16 }}>
						<Switch
							checked={onlyShowLabelMax}
							onChange={( checked ) => onChange( checked, 'onlyShowLabelMax', setOnlyShowLabelMax( checked ) )}
						></Switch>
					</FormItem>
					<FormItem label="显示最小值" name="onlyShowLabelMin" labelAlign="left" labelCol={{ span: 8 }} wrapperCol={{ span: 16 }}>
						<Switch
							checked={onlyShowLabelMin}
							onChange={( checked ) => onChange( checked, 'onlyShowLabelMin', setOnlyShowLabelMin( checked ) )}
						></Switch>
					</FormItem>

					<FormItem label="标签字体" name="chartLabelFont" labelAlign="left" labelCol={{ span: 8 }} wrapperCol={{ span: 16 }}>
						<Editor
							config={config}
							form={form}
							onValuesChange={onValuesChange}
							fontFamilyName="labelFontFamily"
							fontSizeName="labelFontSize"
							fontColorName="labelFontColor"
							boldName="labelFontBold"
							italicName="labelFontItalic"
							fontConfig={fontConfig}
						/>
					</FormItem>
					{
						config.data.lineType !== 'basic' && (
							<>
								<FormItem label="标记样式" name="chartLabelMarkType" labelAlign="left" labelCol={{ span: 8 }} wrapperCol={{ span: 16 }}>
									<Select defaultValue='circle'>
										<Option value="circle">实心圆</Option>
										<Option value="hollowCircle">空心圆</Option>
										<Option value="diamond">菱形</Option>
										<Option value="triangle">三角形</Option>
										<Option value="square">正方形</Option>
									</Select>
								</FormItem>
								<FormItem label="标记大小" name="chartLabelMarkSize" labelAlign="left" labelCol={{ span: 8 }} wrapperCol={{ span: 16 }}>
									<InputNumber min={0} defaultValue={5}></InputNumber>
								</FormItem>
								<FormItem label="标记颜色" name="chartLabelMarkColor" labelAlign="left" labelCol={{ span: 8 }} wrapperCol={{ span: 16 }}>
									<InputColorPicker
										color={chartLabelMarkColor}
										change={onColorChange}
									></InputColorPicker>
								</FormItem>
							</>

						)
					}

				</>
			)}
		
		</div>
	);
};

export default React.memo( LineLabelSetting );
